package com.guhappy.action.contest;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.interceptor.ServletRequestAware;

import com.guhappy.action.model.ListValue;
import com.opensymphony.xwork2.ActionSupport;

public class DeleteContestItemAction extends ActionSupport implements ServletRequestAware {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private HttpServletRequest request;
	private String name;
	private List contestlist = new ArrayList<ListValue>();
	
	@Action(value = "joinContestDeleteAction", results = {
			@Result(name = "error", location = "/pages/simpleechoerror.jsp"),
			@Result(name = "success", type = "redirectAction", params = {
					"actionName", "joinContest" }) })
	
	public String execute() {
		if (name != null && !name.trim().equals("")) {
			if (null != request.getSession().getAttribute("contestList"))
				{
					contestlist = (List) request.getSession().getAttribute("contestList");
					Iterator it = contestlist.iterator();
					while (it.hasNext()){
						ListValue obj = (ListValue) it.next();
						if (obj.getMyKey().equals(name)){
							contestlist.remove(obj);
							request.getSession().setAttribute("contestList",contestlist);
							break;
						}
					}
				}
		}
		
		return SUCCESS;
		
	}

	public void setServletRequest(HttpServletRequest arg0) {
		this.request = arg0;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}
